package top.birdhk.TestAPI.source;

import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import top.birdhk.TestAPI.beans.SensorReading;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class SourceCollection {

    public static void main(String[] args) throws Exception {
        // 创建执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        List<SensorReading> sensorReadings = Arrays.asList(
                new SensorReading("s1", 1747718201L, 15.4),
                new SensorReading("s2", 1747718202L, 20.4),
                new SensorReading("s3", 1747718203L, 38.4)
        );

        // 从集合中读取数据
        DataStreamSource<SensorReading> dataStream = env.fromCollection(sensorReadings);

        DataStreamSource<Integer> integerDataStreamSource = env.fromElements(1, 2, 3, 4, 5);


        // 打印输出
        dataStream.print("data");

        integerDataStreamSource.print("int");


        env.execute("job name");


    }


}
